//MLGB
define('oneJs',['jquery','indexJsBoot'],function($,boot){
    var one={
        init:function(){
            console.log("111111111111");
            var td='<td class="tdnot"><span>编辑</span><span>删除</span></td>';
            var arr=[1];
            $.ajax({
                url:"https://zhusirs.gitee.io/Houtai/json/one.json",
                type:"post",
                dataType:"json",
                success:function(data){
                    // 四个大对象
                    $.each(data,function(index,item){
                        var trone=`<tr class="otab-center1 otab-bold"><th>${item.a_name}</th><td>${item.a_head.a_headleft}</td> <td>${item.a_head.a_headright}</td>${td}</tr>`;
                        var trone1=`<tr class="otab-center2 otab-bold"><th> </th><td>${item.b_head.a_headleft}</td> <td>${item.b_head.a_headright}</td>${td}</tr>`;

                        $(".o-table").append(trone,trone1);
                    });
                    // one对象里的小对象
                    $.each(arr,function(i,v){
                        var trone2=`<tr class="otab-center3 otab-bold"><th> </th><td>${data.one.c_head.a_headleft}</td> <td>${data.one.c_head.a_headright}</td>${td}</tr>`;
                        //console.log(data.one.c_head)
                        var trone3=`<tr class="otab-center4 otab-bold"><th> </th><td>${data.one.d_head.a_headleft}</td> <td>${data.one.d_head.a_headright}</td>${td}</tr>`;
                        var trone4=`<tr class="otab-center5 otab-bold"><th> </th><td>${data.one.e_head.a_headleft}</td> <td>${data.one.e_head.a_headright}</td>${td}</tr>`;
                        var trone5=`<tr class="otab-center6 otab-bold"><th> </th><td>${data.one.f_head.a_headleft}</td> <td>${data.one.f_head.a_headright}</td>${td}</tr>`;

                        $(trone2).insertAfter($(".otab-center2:eq(0)"));
                        $(trone3).insertAfter($(".otab-center3:eq(0)"));
                        $(trone4).insertAfter($(".otab-center4:eq(0)"));
                        $(trone5).insertAfter($(".otab-center5:eq(0)"));
                    });
                    // one对象里的小小对象
                    $.each(data.one.a_text,function(i,v){
                        //console.log(data.one.a_text)
                        var trone2=`<tr class="otab-centerone1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center2:eq(0)"));
                    });
                    $.each(data.one.b_text,function(i,v){
                        var trone2=`<tr class="otab-centerone1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center3:eq(0)"));
                    });
                    $.each(data.one.c_text,function(i,v){
                        var trone2=`<tr class="otab-centerone1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center4:eq(0)"));
                    });
                    $.each(data.one.d_text,function(i,v){
                        var trone2=`<tr class="otab-centerone1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center5:eq(0)"));
                    });
                    $.each(data.one.e_text,function(i,v){
                        var trone2=`<tr class="otab-centerone1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center6:eq(0)"));
                    });
                    $.each(data.one.f_text,function(i,v){
                        var trone2=`<tr class="otab-centerone1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center1:eq(1)"));
                    });
                    // two对象里的小对象
                    $.each(arr,function(i,v){
                        var trone2=`<tr class="otab-center3 otab-bold"><th> </th><td>${data.two.c_head.a_headleft}</td> <td>${data.two.c_head.a_headright}</td>${td}</tr>`;
                        $(trone2).insertAfter($(".otab-center2:eq(1)"));
                    });
                    // two对象里的小小对象
                    $.each(data.two.a_text,function(i,v){
                        //console.log(data.one.a_text)
                        var trone2=`<tr class="otab-centertwo1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center2:eq(1)"));
                    });
                    $.each(data.two.b_text,function(i,v){
                        var trone2=`<tr class="otab-centertwo1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center3:eq(1)"));
                    });
                    $.each(data.two.c_text,function(i,v){
                        var trone2=`<tr class="otab-centertwo1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center1:eq(2)"));
                    });
                    // three对象里的小对象
                    $.each(arr,function(i,v){
                        var trone2=`<tr class="otab-center3 otab-bold"><th> </th><td>${data.three.c_head.a_headleft}</td> <td>${data.three.c_head.a_headright}</td>${td}</tr>`;
                        $(trone2).insertAfter($(".otab-center2:eq(2)"));
                    });
                    // three对象里的小小对象
                    $.each(data.three.a_text,function(i,v){
                        //console.log(data.one.a_text)
                        var trone2=`<tr class="otab-centerthree1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center2:eq(2)"));
                    });
                    $.each(data.three.b_text,function(i,v){
                        var trone2=`<tr class="otab-centerthree1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center3:eq(2)"));
                    });
                    $.each(data.three.c_text,function(i,v){
                        var trone2=`<tr class="otab-centerthree1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center1:eq(3)"));
                    });
                    // four对象里的小小对象
                    $.each(data.four.a_text,function(i,v){
                        //console.log(data.one.a_text)
                        var trone2=`<tr class="otab-centerthree1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-center2:eq(3)"));
                    });
                    var tr='<tr class="otab-footer"></tr>';
                    $(".o-table").append(tr);
                    $.each(data.four.b_text,function(i,v){
                        var trone2=`<tr class="otab-centerfour1"><th> </th><td>${v.a}</td> <td>${v.b}</td>${td}</tr>`;
                        $(trone2).insertBefore($(".otab-footer"));
                    });
                    $(".otab-centerone1,.otab-centertwo1,.otab-centerthree1,.otab-centerfour1").addClass("notspan");
                //    合并标题的rowspan
                //    $(".otab-center1:eq(0)").nextAll(".otab-centerone1").css({background:"red"});
                //    var all=$(".otab-center1:eq(0)").nextAll(".otab-centerone1");
                //    console.log(all.length);
                //    $(".otab-center1:eq(0) th").attr("rowspan",12);

                    //    点击编辑和删除   一行
                    $("table").on("click",".notspan td span:last-child",function(){
                        if(window.confirm("确定删除？") == true){
                            $(this).parents("tr").remove();
                        }
                    });

                    //    点击编辑和删除   一列
                    //function fun(num){
                    //    var num=num;
                    //    return function b(){
                    //        num++;
                    //        if(window.confirm("确定删除整个列表？") == true){
                    //            arguments.callee();
                    //            $(this).parents(".otab-bold").nextUntil(`.otab-center2:eq(${num-1})`).remove();
                    //            $(this).parents(".otab-bold").remove();
                    //        }
                    //        return b
                    //    }
                    //}
                    //$.each(otab,function(i,v){
                    //    //console.log(v)
                    //    $(otab).on("click","td span:last-child",function(){
                    //        var index=$(otab).index();
                    //        console.log(index);
                    //            if(window.confirm("确定删除整个列表？") == true){
                    //                //arguments.callee();
                    //                $(this).parents(".otab-bold").nextUntil(`.otab-bold:eq(1)`).remove();
                    //                $(this).parents(".otab-bold").remove();
                    //            }
                    //    })
                    //});
                    //  不太完整的点击删除   只能按顺序一个一个来  后期调整上面闭包例子完善
                    var otab=$(".otab-bold");
                    for(var i=0,a=otab.length;i<a;i++){
                        otab[i].index=i;
                        //console.log(otab.length)
                        $($(otab)[i]).on("click","td span:last-child",function(q){
                            var ins=$(this).parents(".otab-bold").index([this.index]);
                            //arguments.callee();
                            console.log(ins)
                            if(window.confirm("确定删除整个列表？") == true){
                                $(this).parents(".otab-bold").nextUntil(".otab-bold:eq("+([this.index]+1)+")").remove();
                                $(this).parents(".otab-bold").remove();
                            }
                        })
                    }
                //    点击编辑更换文字   这里有bug未解决
                    var that;
                    $("table").on("click","td span:first-child",function(){
                        that=this;
                        var t = document.documentElement.scrollTop || document.body.scrollTop;
                        $("html,body").scrollTop(0);
                        console.log($(that).parents("tr").find("td:nth-of-type(1)").text());
                        $(".con-position").show();
                        $(".o-footer").find("dt:nth-child(1) input").val($(this).parents("tr").find("th").text());
                        $(".o-footer").find("dt:nth-child(2) input").val($(this).parents("tr").find("td:nth-of-type(1)").text());
                        $(".o-footer").find("dt:nth-child(3) input").val($(this).parents("tr").find("td:nth-of-type(2)").text());
                        if($(".o-footer").find("dt:nth-child(1) input").val() == " " || $(".o-footer").find("dt:nth-child(1) input").val() == ""){
                            $(".o-footer").find("dt:nth-child(1) input").val("");
                            //$(this).css({background:"red"})
                        }
                        setTimeout(function(){
                            $(".con-position").hide();
                            $(".o-footer").show();
                        },100);

                    });
                    $(".o-footer>p").on("click",function(){
                        //console.log(that)
                        $(that).parents("tr").find("th").text($(this).prev().find("dt:nth-child(1) input").val());
                        $(that).parents("tr").find("td:nth-of-type(1)").text($(this).prev().find("dt:nth-child(2) input").val());
                        $(that).parents("tr").find("td:nth-of-type(2)").text($(this).prev().find("dt:nth-child(3) input").val());
                        $(this).next().show();
                    });
                    $(".o-fanhui").click(function(){
                        $(".o-footer").hide()
                    });
                    $(".hisdiv").click(function(){
                        $(this).parents(".o-open,.o-footer").hide();
                    });
                    $(".op-close").click(function(){
                        $(this).parents(".o-open").hide();
                    });


                },
                error:function(){
                    console.log("数据请求失败，点击确定重试");
                    // history.go(0);
                }

            });

        }
    };
    return one;
});
